package org.cttic.visualization.visualization.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author shkstart
 * @create 2020-04-29 18:22
 */
public class DateUtil {
//    public static void main(String[] args) throws ParseException {
//        System.out.println(dataToDate("2020-05-08 20:00:00"));
//
//
//    }
    public static String timeToT(String time){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime ldt = LocalDateTime.parse(time,df);
        if (ldt.toString().length()==16){
            return ldt.toString()+":00";
        }
        return ldt.toString();
    }
    public static String TtoTime(String Ttime){
        StringBuilder stringBuilder = new StringBuilder(Ttime);
        StringBuilder replace = stringBuilder.replace(10, 11, " ");
        return replace.toString();
    }
    public static String dateToStamp(String s) throws ParseException {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }
    public static String StampToDate(long stamp){
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(stamp);
        return format;
    }
    public static String StampToMonth(long stamp){
        String format = new SimpleDateFormat("yyyyMM").format(stamp);
        return format;
    }
    public static Date dataToDate(String data) throws ParseException {
        Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(data);
        return parse;
    }

    /**
     *
     * @param timeStr  yyyy-MM-dd HH:mm:ss
     * @return         yyyy-MM-ddTHH:mm:ss
     */
    public static String timeIncrT(String timeStr){
        StringBuilder stringBuilder = new StringBuilder(timeStr);
        StringBuilder replace = stringBuilder.replace(10, 11, "T");
        return replace.toString();
    }



}
